﻿using UnityEngine;
using System.Collections.Generic;
using Dict.Blo;
using Dict.DataModel;

namespace UI
{
    public class UIWorldSeed
    {
        private int level;
        public BaseAttributeData attributeData = new BaseAttributeData();

        public void SetLevel(int level)
        {
            this.level = level;
            var wd = TableWorldSeedBlo.GetWorldSeedData(level);
            attributeData.Reset();
            char[] sp = { ','};
            for(int i =0; i < wd.Count;++i)
            {
                if(wd[i].type == 1)
                {
                    string[] ad = wd[i].get.Split(sp);
                    if(ad.Length != 2)
                    {
                        Debug.LogError("world seed data error,id " + wd[i].id);
                    }
                    else
                    {
                        //attributeData.SetProp(ad[0],double.Parse(ad[1]));
                        attributeData.AddProp(ad[0], double.Parse(ad[1]));
                    }
                }
            }
        }

        public List<TableWorldSeed> GetCurrentGroupSeed(out bool maxLevel)
        {
            TableWorldSeed tws = TableWorldSeedBlo.GetWorldSeedById((level+1).ToString());
            if(tws == null)
            {
                maxLevel = true;
                tws = TableWorldSeedBlo.GetWorldSeedById(level.ToString());
            }
            else
            {
                maxLevel = false;
            }
            return TableWorldSeedBlo.GetDataByGroup(tws.groupId);
        }

        public List<TableWorldSeed> GetPreviewGroupSeed()
        {
            if (level < 5) return null;

            int remainder = level % 5;
            int preview = level - remainder;
            TableWorldSeed tws = TableWorldSeedBlo.GetWorldSeedById((preview).ToString());
            
            return TableWorldSeedBlo.GetDataByGroup(tws.groupId);
        }

    }
}